/**
 * Created by ${PRODUCT_NAME}.
 * User: skylerparr
 * Date: 12/19/10
 * Time: 4:47 PM
 * To change this template use File | Settings | File Templates.
 */
package com.thoughtorigin.deeplink {
import com.asual.swfaddress.SWFAddressEvent;

import com.thoughtorigin.service.Message;

import flash.events.Event;

import org.flexunit.asserts.assertEquals;
import org.flexunit.asserts.assertNotNull;
import org.flexunit.asserts.assertTrue;
import org.flexunit.async.Async;

public class ConfigurableDeeplinkerTest {

    private var _deeplinker: TestableConfigurableDeeplinker;

    [Before]
    public function setup(): void {
        _deeplinker = new TestableConfigurableDeeplinker();
    }

    [After]
    public function tearDown(): void {
        _deeplinker = null;
    }

    [Test]
    public function shouldInitialize(): void {
        _deeplinker.init();
        _deeplinker.mockBrowserHistory.simulateInit();
        assertTrue(_deeplinker.mockBrowserHistory._setHistory);
    }

    [Test(async)]
    public function shouldHandleAddressChange(): void {
        _deeplinker.init();
        _deeplinker.mockBrowserHistory.simulateInit();
        _deeplinker.defaultDeeplink = "/";
        var handler: Function = Async.asyncHandler(this, function(m : Message, o: Object): void {
            assertNotNull(m);
        }, 300);
        _deeplinker.addEventListener("CommandEvent", handler);
        _deeplinker.mockBrowserHistory.simulateChange();
    }
}
}

import com.thoughtorigin.deeplink.BrowserHistory;
import com.thoughtorigin.deeplink.ConfigurableDeeplinker;
import com.thoughtorigin.deeplink.mock.MockBrowserHistory;

class TestableConfigurableDeeplinker extends ConfigurableDeeplinker {

    public var mockBrowserHistory: MockBrowserHistory = new MockBrowserHistory();

    override protected function get browserHistory():BrowserHistory {
        return mockBrowserHistory;
    }

}
